package com.rainng.coursesystem.repository;

import com.rainng.coursesystem.model.PaperItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PaperRepository extends JpaRepository<PaperItem, Integer> {
    @Query("SELECT p FROM PaperItem p LEFT JOIN FETCH p.questions WHERE p.id = :paperId")
    PaperItem findPaperWithQuestions(@Param("paperId") Integer paperId);

    @Query("SELECT p.id, p.name, p.description FROM PaperItem p")
    List<Object[]> findAllProjectedBy(); // 返回 Object[] 数组

    List<PaperItem> findByCourseId(Long courseId);
}